DicomObjects.NET.8.48 Documentation
DicomObjects Namespace / DicomDataSet Class / Write Method / Write(IEnumerable<Byte[]>,String,Int32) Method

Collection of byte arrays to write large dataset to

Specifies the full UID of the transfer syntax with which the file is to be saved when Part 10 format is used. If omitted, the little-endian explicit VR transfer syntax is used.

Size of each individual buffers in the collection
Example

In This Topic
    Write(IEnumerable<Byte[]>,String,Int32) Method
    In This Topic
    Writes dataset to an an enumerable byte arrays with specified transfer syntax and byte array length. This is useful if you want to have byte arrays for large data. FileStream or something similar would be preferable than holding everything in memory.
    Syntax
    'Declaration
     
    
    Public Overloads Sub Write( _
       ByRef arrays As System.Collections.Generic.IEnumerable(Of Byte()), _
       ByVal TransferSyntax As System.String, _
       Optional ByVal pagedBufferSize As System.Integer _
    ) 
    public void Write( 
       out System.Collections.Generic.IEnumerable<byte[]> arrays,
       System.string TransferSyntax,
       System.int pagedBufferSize
    )

    Parameters

    arrays

    Collection of byte arrays to write large dataset to

    TransferSyntax

    Specifies the full UID of the transfer syntax with which the file is to be saved when Part 10 format is used. If omitted, the little-endian explicit VR transfer syntax is used.

    pagedBufferSize
    Size of each individual buffers in the collection
    Remarks

    Data may subsequently be read by the Read method or by other DICOM software.

    Example
    DicomDataSet ds = new DicomDataSet();       
    string filename = "Output_Dataset.dcm";
    string transferSyntax = TransferSyntaxes.ExplicitVRLittleEndian;      
    int pagedBufferSize = 65535;
                        
    string pixelTransferSyntax = TransferSyntaxes.ExplicitVRLittleEndian;
    ds.Add(Keyword.SamplesPerPixel, 1);
    ds.Add(Keyword.PhotometricInterpretation, "MONOCHROME2");
    ds.Add(Keyword.Rows, 512);
    ds.Add(Keyword.Columns, 512);
    ds.Add(Keyword.PixelSpacing, new float[] { 0.684f, 0.684f });
    ds.Add(Keyword.BitsAllocated, 16);
    ds.Add(Keyword.BitsStored, 12);
    ds.Add(Keyword.HighBit, 11);
    ds.Add(Keyword.PixelRepresentation, 0);
    ds.Add(Keyword.WindowCenter, new int[] { 35, 50 });
    ds.Add(Keyword.WindowWidth, new int[] { 350, 150 });
    ds.Add(Keyword.RescaleIntercept, -1200);
    ds.Add(Keyword.RescaleSlope, 1);
    ds.SetPixelData(pixelTransferSyntax, getData);   
                        
    ds.Write(out IEnumerable<byte[]> chunks, transferSyntax, pagedBufferSize);
                
    using (FileStream fs = new FileStream("Output_Dataset.dcm", FileMode.Create, FileAccess.Write))
    {
        foreach (var chunk in chunks)
            fs.Write(chunk, 0, chunk.Length);
    }
                        
    // Method
    private Stream getData(int arg)
    {
        return new FileStream("pixel.data", FileMode.Open, FileAccess.Read, FileShare.Read);
    }
    Requirements

    Target Platforms: .NET CLR 4.8 or higher

    See Also